﻿
using XYTXL.API;
using XYTXL.AppCode;
using XYTXL.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



namespace XYTXL
{
    public partial class Login : System.Web.UI.Page
    {
        public string strNameL
        {
            get { return Request.QueryString["userid"] ?? "-1"; }
        }

        public string strPassWord
        {
            get { return Request.QueryString["password"] ?? "-1"; }
        }
        public string strCode
        {
            get { return Request.QueryString["code"] ?? "-1"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }


        protected void btLogin_Click(object sender, EventArgs e)
        {
            string strUserName = Request["username"].ToString();
            string strPassWord = Request["userpasd"].ToString();
            string strCode = Request["code"].ToString();

            if (strUserName == "" || strPassWord == "" || strCode == "")
            {
                lblMsg.Text = "用户名、密码和验证码不能为空";
                return;
            }
            else
            {
                if (strCode.ToUpper() != Session["chkcode"].ToString()) 
                {
                    lblMsg.Text = "验证码不正确";
                    return;
                }
            }
             
            if (new JH_Auth_UserB().GetEntity(d => d.UserName == strUserName && d.UserPass == strPassWord && d.IsUse == "Y") != null)
            {
                Session["UserName"] = strUserName;
                if (Session["loginUrl"] != null && !string.IsNullOrEmpty(Session["loginUrl"].ToString()))
                { 
                    string url = Session["loginUrl"].ToString();
                    Response.Redirect(url, false);
                }
                else
                {

                    Response.Redirect("/View/IndexNTab.aspx", false);
                }

            }
            else
            {
                lblMsg.Text = "用户名或密码错误";
            }
        }

    }
}